package com.example.demo.aop;

import com.example.demo.entity.enums.CodeEnum;
import com.example.demo.util.RUtil;
import com.example.demo.vo.R;
import com.example.exceptions.RException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: demo
 * @description: 异常捕获
 * @author: 陈程猿
 * @create: 2024-12-11 09:56
 **/

@RestControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler(value = Exception.class)
    public R handle(Exception e){
        if (e instanceof RException){
            RException re=(RException) e;
            return RUtil.error(re.getCode(),re.getMessage());
        }
        return RUtil.error(CodeEnum.UNKNOWN_ERROR);
    }

}
